<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Array.filter() + indexOf</title>
    <script>
        // distinct.js
		let arr1 = Array.from(new Array(100000), (x, index)=>{
    		return index
		})

		let arr2 = Array.from(new Array(50000), (x, index)=>{
    		return index+index
		})

		let start = new Date().getTime()
		console.log('开始数组去重')

		function distinct(a, b) {
    		// 数组去重
    		//1.Array.filter() + indexOf
    		let arr = a.concat(b);
    		return arr.filter((item, index)=> {
        		return arr.indexOf(item) === index
    		})
		}

		console.log('去重后的长度', distinct(arr1, arr2).length)

		let end = new Date().getTime()
		console.log('耗时', end - start)
    </script>
</head>

<body>

</body>

</html>